package operate

import (
	"context"
	"fmt"
	"strconv"
	"strings"

	"MBTI/api/internal/svc"
	"MBTI/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetTopicLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetTopicLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetTopicLogic {
	return &GetTopicLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetTopicLogic) GetTopic(req *types.GetTopicReq) (resp *types.Reply, err error) {
	// todo: add your logic here and delete this line
	fmt.Println("读题")
	var _Topic []Topic
	for index := 1; index < 94; index++ {
		i := strconv.Itoa(index)
		var topic Topic
		All, err := l.svcCtx.Redis.Get(i).Result()
		// fmt.Println(title)
		if err != nil {
			fmt.Println(err)
		}
		s := strings.Split(All, "&")
		topic.Title = s[0]
		topic.SectionA = s[1]
		topic.SectionB = s[2]
		topic.ValueA = s[3]
		topic.ValueB = s[4]
		_Topic = append(_Topic, topic)
	}
	// fmt.Println(Topic)
	return &types.Reply{Code: 100,
		Data: map[string]interface{}{
			"Topic": _Topic,
		},
		Msg: "读取题目成功！"}, nil
}

type Topic struct {
	Title    string
	SectionA string
	SectionB string
	ValueA   string
	ValueB   string
}
